package com.rx.common.listener;

import java.util.List;

import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.rx.biz.sys.PrivilegeBiz;
import com.rx.common.Constants;
import com.rx.entity.sys.Privilege;
import com.rx.util.BeanUtils;

/**
 * 项目初始化监听器
 * 
 * @author Renxin
 * 
 */
public class InitListener implements ServletContextListener {

	protected Logger logger = LoggerFactory.getLogger(getClass());

	public void contextInitialized(ServletContextEvent sce) {
		// 初始化后台过滤列表
		try {
			PrivilegeBiz biz = (PrivilegeBiz) BeanUtils.getBean("privilegeBiz");
			List<Privilege> privileges = biz.search();
			for (Privilege privilege : privileges) {
				Constants.ADMIN_FILTER_PATH.add(privilege.getUrl());
			}
		} catch (Exception e) {
			logger.error("[初始化后台过滤列表出错:{}]", e.getMessage());
		}
	}

	public void contextDestroyed(ServletContextEvent sce) {

	}

}
